﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Collect : ICollect
    {
        public void Add(Collect item)
        {
            CakeEntities db = new CakeEntities();
            db.Collect.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Collect.Remove(db.Collect.Find(id));
            db.SaveChanges();
        }

        public Collect FindById(int id)
        {
            return new CakeEntities().Collect.Find(id);
        }

        public List<Collect> GetAll()
        {
            return new CakeEntities().Collect.ToList();
        }

        public void Updata(int id, Collect item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Collect.Find(id);
            if (data!=null)
            {
                data.GoodsId = item.GoodsId;
                data.CreateDate = item.CreateDate;
                data.CustomerId=item.CustomerId;
                data.Price = item.Price;
                db.SaveChanges();
            }
        }
    }
}
